package com.java110.fee.cmd.cheque;

import com.alibaba.fastjson.JSONObject;
import com.java110.core.annotation.Java110Cmd;
import com.java110.core.context.ICmdDataFlowContext;
import com.java110.core.event.cmd.Cmd;
import com.java110.core.event.cmd.CmdEvent;
import com.java110.core.log.LoggerFactory;
import com.java110.intf.fee.IChequeInnerServiseSMO;
import com.java110.po.cheque.ChequePo;
import com.java110.utils.exception.CmdException;
import com.java110.utils.util.Assert;
import com.java110.utils.util.BeanConvertUtil;
import com.java110.vo.ResultVo;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;

import java.text.ParseException;

/**
 * 票据管理：删除
 * 服务编码：cheque.listCheque
 */
@Java110Cmd(serviceCode = "cheque.deleteCheque")
public class DeleteChequeCmd extends Cmd {
    private static Logger logger = LoggerFactory.getLogger(DeleteChequeCmd.class);

    @Autowired
    private IChequeInnerServiseSMO chequeInnerServiseSMOImpl;
    @Override
    public void validate(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException, ParseException {
        Assert.jsonObjectHaveKey(reqJson, "chequeId", "chequeId不能为空");
        Assert.jsonObjectHaveKey(reqJson, "communityId", "communityId不能为空");
    }

    @Override
    public void doCmd(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException, ParseException {
        ChequePo chequePo = BeanConvertUtil.covertBean(reqJson,ChequePo.class);
        int flag =  chequeInnerServiseSMOImpl.deleteCheque(chequePo);
        if (flag < 1) {
            throw new CmdException("删除数据失败");
        }
        context.setResponseEntity(ResultVo.success());
    }
}
